package cn.itcast.service.cargo.impl;

import cn.itcast.dao.base.StateDao;
import cn.itcast.domain.base.State;
import cn.itcast.domain.base.StateExample;
import cn.itcast.service.cargo.StateService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

@Service
public class StateServiceImpl implements StateService {

    @Autowired
    private StateDao stateDao;
    @Override
    public PageInfo<State> findAll(StateExample stateExample,Integer pageNum, Integer pageSize) {
        //1. 设置开始页与页面大小
        PageHelper.startPage(pageNum,pageSize);
        List<State> list = stateDao.selectByExample(stateExample);
        PageInfo<State> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<State> findAllState(StateExample stateExample) {
        return stateDao.selectByExample(stateExample);
    }

    @Override
    public void save(State state) {
        state.setId(UUID.randomUUID().toString());
        stateDao.insertSelective(state);
    }

    @Override
    public void update(State state) {
        stateDao.updateByPrimaryKeySelective(state);
    }

    @Override
    public State findById(String id) {
        return stateDao.selectByPrimaryKey(id);
    }

    @Override
    public void delete(String id) {
        stateDao.deleteByPrimaryKey(id);
    }
}
